<template>
  <div class="tab-content">
    <div class="list">
      <div class="item" v-for="item in dataSort" :key="item.province_name">
        <div class="name">{{ item.province_name }}</div>
        <div class="data">
          <div class="line line1" :style="{ width: item.width1 + '%' }">当前商机:{{ item.total }}</div>
          <div class="line line2" :style="{ width: item.width2 + '%' }">无人问津:{{ item.no_visit }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'heatStatistics',
  props: {
    tabData: Array,
  },
  computed: {
    dataSort() {
      if (this.tabData && this.tabData.length > 0) {
        const arr = this.tabData.sort((a, b) => {
          return b.total - a.total
        })
        const max = arr[0].total
        const allWidth = 590
        const barWidth = 470
        const lableWidth = 120
        arr.forEach((item) => {
          item.width1 = ((((item.total / max) * barWidth + lableWidth) / allWidth) * 100).toFixed(2)
          item.width2 = ((((item.no_visit / max) * barWidth + lableWidth) / allWidth) * 100).toFixed(2)
        })
        return arr
      } else {
        return []
      }
    },
  },
  data() {
    return {}
  },
  created() {},
  mounted() {},
  methods: {},
}
</script>

<style scoped lang="scss">
.tab-content {
  width: 100%;
  padding: 30rpx 24rpx;
  .list {
    width: 100%;
    .item {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-bottom: 20rpx;
      .name {
        width: 100rpx;
      }
      .data {
        flex: 1 1 auto;
        margin-left: 10rpx;

        .line {
          height: 36rpx;
          font-size: 20rpx;
          display: flex;
          justify-content: flex-start;
          align-items: center;
          padding-left: 10rpx;
          color: #ffffff;
          border-radius: 0 14rpx 14rpx 0;
        }
        .line1 {
          background: #409eff;
        }
        .line2 {
          background: #67c23a;
        }
      }
    }
  }
}
</style>
